diff --git a/scenes/__pycache__/multiprocessing.cpython-33.pyc b/scenes/__pycache__/multiprocessing.cpython-33.pyc index 7645044adc3b046eaaed0994c6f051d98fc9fd62..069cae04b5d3f178ffa85e6fa38aedecf12af2ac 100644 Binary files a/scenes/__pycache__/multiprocessing.cpython-33.pyc and b/scenes/__pycache__/multiprocessing.cpython-33.pyc differ diff --git a/scenes/__pycache__/multiprocessing_2.cpython-33.pyc b/scenes/__pycache__/multiprocessing_2.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3b1bc7d67f06e608fcd0f9976d850e582e3233ed Binary files /dev/null and b/scenes/__pycache__/multiprocessing_2.cpython-33.pyc differ diff --git a/scenes/__pycache__/square.cpython-33.pyc b/scenes/__pycache__/square.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..835a68db460c108aac51e15ff355cbee1d6990a5 Binary files /dev/null and b/scenes/__pycache__/square.cpython-33.pyc differ diff --git a/scenes/__pycache__/three_triangles.cpython-33.pyc b/scenes/__pycache__/three_triangles.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c55f41e1296e48281a1596b7e34494b1b15d06e Binary files /dev/null and b/scenes/__pycache__/three_triangles.cpython-33.pyc differ diff --git a/scenes/__pycache__/with_multiprocessing.cpython-33.pyc b/scenes/__pycache__/with_multiprocessing.cpython-33.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6fde5bcf463542dd0af33171a0216e504f6d35f6 Binary files /dev/null and b/scenes/__pycache__/with_multiprocessing.cpython-33.pyc differ diff --git "a/scenes/carr\303\251.png" "b/scenes/carr\303\251.png" new file mode 100644 index 0000000000000000000000000000000000000000..8385ce8dd579179058a2b02d721e72b2a59b86c1 Binary files /dev/null and "b/scenes/carr\303\251.png" differ diff --git a/scenes/one_sphere.py b/scenes/one_sphere.py index 448b2e328e674281d70a5ae1e92d6073ed040c8f..e8717f0a6a0c5876adeb778ae562d23422c0e7f8 100644 --- a/scenes/one_sphere.py +++ b/scenes/one_sphere.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # Show to python where to find the modules import sys sys.path.append('..') diff --git a/scenes/square.py b/scenes/square.py new file mode 100644 index 0000000000000000000000000000000000000000..4371d7999071dbcb13e3382940bb6bca49420241 --- /dev/null +++ b/scenes/square.py @@ -0,0 +1,41 @@ +# Show to python where to find the modules +import sys +sys.path.append('..') + +from camera import Camera +from scene import * +from light import * +from raytracer import * +import numpy as np +from matplotlib.image import imsave +import itertools +import multiprocessing + +def trace_ray_mutliprocess(t): + (i, j, camera, scene, nb_reflexion) = t + return np.array(trace_ray(camera.ray_at(i, j), scene, camera, nb_reflexion).coord()) + +(nx, ny, nb_reflexion) = (200, 200, 20) +camera = Camera(nx, ny, 1) +materiau_sphere_blanche = Material(Vector([1,1,1]), 0.2, 1, 1, 20, 0) +v0 = Vector([-1,-1,2]) +v1 = Vector([1,-1,2]) +v2 = Vector([-1,1,2]) +v3 = Vector([1,1,2]) +carre_blanc = Quad(v0,v1,v2,v3,materiau_sphere_blanche) +scene = Scene() +lumiere = Spotlight(Vector([0,0,0]), Vector([0,0,1])) +scene.add_object(carre_blanc) +scene.add_light(lumiere) +affiche = np.zeros((nx, ny, 3)) +rows = list(range(nx)) +columns = list(range(ny)) +carte = list(itertools.product(rows, columns, [camera], [scene], [nb_reflexion])) + +if __name__ == '__main__': + pool = multiprocessing.Pool(4) + affiche_map = pool.map(trace_ray_mutliprocess, carte) + pool.close() + pool.join() + affiche = np.array(affiche_map).reshape(nx, ny, 3) + imsave('carré.png', affiche) diff --git a/scenes/triangle.png b/scenes/triangle.png new file mode 100644 index 0000000000000000000000000000000000000000..4903dab3f31361c73814004329e1137c9c72c6d7 Binary files /dev/null and b/scenes/triangle.png differ diff --git a/scenes/two_spheres_processing.png b/scenes/two_spheres_processing.png new file mode 100644 index 0000000000000000000000000000000000000000..4e826b11ab21bf10d09e3815d63b7989a70ebfe5 Binary files /dev/null and b/scenes/two_spheres_processing.png differ diff --git a/scenes/with_multiprocessing.py b/scenes/with_multiprocessing.py new file mode 100644 index 0000000000000000000000000000000000000000..cb2dcff0ec4c2f6f8e8ce14b64fb369e825459dd --- /dev/null +++ b/scenes/with_multiprocessing.py @@ -0,0 +1,40 @@ +# Show to python where to find the modules +import sys +sys.path.append('..') + +from camera import Camera +from scene import * +from light import * +from raytracer import * +import numpy as np +from matplotlib.image import imsave +import itertools +import multiprocessing + +def trace_ray_mutliprocess(t): + (i, j, camera, scene, nb_reflexion) = t + return np.array(trace_ray(camera.ray_at(i, j), scene, camera, nb_reflexion).coord()) + +(nx, ny, nb_reflexion) = (1000, 1000, 20) +camera = Camera(nx, ny, 1) +materiau_sphere_bleue = Material(Vector([0,0,1.]), .5, .5, .5, 1000,.1) +materiau_sphere_rouge = Material(Vector([1,0,0]), .5, .5, .5, 1000, .3) +sphere_bleue = Sphere(Vector([0,0,3]), .8, materiau_sphere_bleue) +sphere_rouge = Sphere(Vector([.5,.5,2]), .5, materiau_sphere_rouge) +scene = Scene() +lumiere = Spotlight(Vector([1,1,0]), Vector([1,1,1])) +scene.add_object(sphere_bleue) +scene.add_object(sphere_rouge) +scene.add_light(lumiere) +affiche = np.zeros((nx, ny, 3)) +rows = list(range(nx)) +columns = list(range(ny)) +carte = list(itertools.product(rows, columns, [camera], [scene], [nb_reflexion])) + +if __name__ == '__main__': + pool = multiprocessing.Pool(4) + affiche_map = pool.map(trace_ray_mutliprocess, carte) + pool.close() + pool.join() + affiche = np.array(affiche_map).reshape(nx, ny, 3) + imsave('two_spheres_processing.png', affiche)