def main(): # image dimensions (pixel) nx = 200 ny = 100 # number of samples (rays) per pixel ns = 100 # define camera lookfrom = np.array([-3., 3., 3.]) lookat = np.array([0., 0., 0.]) vfov = np.pi/9 aperture = 1. focus_dist = np.linalg.norm(lookat - lookfrom) cam = Camera(lookfrom, lookat, np.array([0., 1., 0.]), vfov, nx / ny, aperture, focus_dist) # define scene geometry scene = SurfaceAssembly() scene.add_object(Sphere(np.array([ 0., 0., 0.]), 0.5, Lambertian(np.array([0.1, 0.2, 0.5])))) scene.add_object(Sphere(np.array([ 1., 0., 0.]), 0.5, Metal(np.array([0.8, 0.6, 0.2]), 1.0))) # imitate hollow glass sphere scene.add_object(Sphere(np.array([-1., 0., 0.]), 0.5, Dielectric(1.5))) scene.add_object(Sphere(np.array([-1., 0., 0.]), -0.45, Dielectric(1.5))) # large sphere imitating ground floor scene.add_object(Sphere(np.array([0., -100.5, 0.]), 100., Lambertian(np.array([0.8, 0.8, 0.0])))) # render image im = render_image(nx, ny, ns, scene, cam) imageio.imwrite('depth_of_field.png', im.transpose((1, 0, 2)))
def generate_and_insert_single_image(x,im_hash): conn = pm.Connection(document_class = SON) db = conn[DB_NAME] im_coll = db['images.files'] im_fs = gridfs.GridFS(db,'images') image_string = rendering.render_image(x['image']) y = SON([('config',x)]) filename = get_filename(x) y['filename'] = filename y['__hash__'] = im_hash im_fs.put(image_string,**y)
def generate_images(outfile,im_hash,config_gen): conn = pm.Connection(document_class = SON) db = conn[DB_NAME] im_coll = db['images.files'] im_fs = gridfs.GridFS(db,'images') remove_existing(im_coll,im_fs,im_hash) X = rendering.config_gen(config_gen) for (i,x) in enumerate(X): if (i/100)*100 == i: print(i,x) image_string = rendering.render_image(x['image']) y = SON([('config',x)]) filename = get_filename(x) y['filename'] = filename y['__hash__'] = im_hash im_fs.put(image_string,**y) createCertificateDict(outfile,{'image_hash':im_hash,'args':config_gen})
def main(): # image dimensions (pixel) nx = 200 ny = 100 # number of samples (rays) per pixel ns = 100 # define camera lookfrom = np.zeros(3) lookat = np.array([0., 0., -1.]) vfov = np.pi / 2 aperture = 0. focus_dist = 1. cam = Camera(lookfrom, lookat, np.array([0., 1., 0.]), vfov, nx / ny, aperture, focus_dist) # define scene geometry scene = SurfaceAssembly() scene.add_object( Sphere(np.array([0., 0., -1.]), 0.5, Lambertian(np.array([0.8, 0.3, 0.3])))) scene.add_object( Sphere(np.array([1., 0., -1.]), 0.5, Metal(np.array([0.8, 0.6, 0.2]), 1.0))) scene.add_object( Sphere(np.array([-1., 0., -1.]), 0.5, Metal(np.array([0.8, 0.8, 0.8]), 0.3))) # large sphere imitating ground floor scene.add_object( Sphere(np.array([0., -100.5, -1.]), 100., Lambertian(np.array([0.8, 0.8, 0.0])))) # render image im = render_image(nx, ny, ns, scene, cam) imageio.imwrite('metal_spheres.png', im.transpose((1, 0, 2)))
def main(): # image dimensions (pixel) nx = 1200 ny = 800 # number of samples (rays) per pixel ns = 10 # define camera lookfrom = np.array([13., 2., 3.]) lookat = np.zeros(3) vfov = np.pi / 9 aperture = 0.1 focus_dist = 10.0 cam = Camera(lookfrom, lookat, np.array([0., 1., 0.]), vfov, nx / ny, aperture, focus_dist) # define scene geometry scene = SurfaceAssembly() # three large spheres scene.add_object( Sphere(np.array([4., 1., 0.]), 1.0, Metal(np.array([0.7, 0.6, 0.5]), 0.))) scene.add_object(Sphere(np.array([0., 1., 0.]), 1.0, Dielectric(1.5))) scene.add_object( Sphere(np.array([-4., 1., 0.]), 1.0, Lambertian(np.array([0.4, 0.2, 0.1])))) # smaller spheres with random parameters for a in range(-11, 12): for b in range(-11, 12): center = np.array([ a + 0.9 * np.random.rand(), 0.2 + 0.1 * np.random.rand(), b + 0.9 * np.random.rand() ]) # random choice between diffusive, metal or dielectric (glass) choose_mat = np.random.choice(3, p=[0.8, 0.15, 0.05]) if choose_mat == 0: # diffusive scene.add_object( Sphere( center, 0.2, Lambertian(np.random.triangular(0., 0.2, 1., size=3)))) elif choose_mat == 1: # metal scene.add_object( Sphere( center, 0.2, Metal(0.5 * (1 + np.random.rand(3)), 0.5 * np.random.rand()))) else: # dielectric (glass) scene.add_object(Sphere(center, 0.2, Dielectric(1.5))) # huge sphere imitating ground floor scene.add_object( Sphere(np.array([0., -1000., 0.]), 1000., Lambertian(np.array([0.5, 0.5, 0.5])))) # render image im = render_image(nx, ny, ns, scene, cam) imageio.imwrite('random_scene.png', im.transpose((1, 0, 2)))