From abbdbe64d12af732983bc11aac772d3d32682bb5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 20 Jan 2020 22:40:44 +0100 Subject: Extract OpenCL setup into Renderer --- fancy_local_sunrise.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'fancy_local_sunrise.py') diff --git a/fancy_local_sunrise.py b/fancy_local_sunrise.py index 39cb292..bdb23b4 100644 --- a/fancy_local_sunrise.py +++ b/fancy_local_sunrise.py @@ -1,17 +1,12 @@ import numpy as np import matplotlib.pyplot as plt -from string import Template -import pyopencl as cl -from pyopencl.cltypes import make_double3 - -mf = cl.mem_flags - -from planets import earth - -from sun import sun_direction from datetime import datetime +from firmament import Renderer +from firmament.planets import earth +from firmament.sun import sun_direction + config = { 'size_x': 1000, 'size_y': 1000, @@ -35,37 +30,20 @@ config = { time_range = (6, 20, 1) -cl_platform = cl.get_platforms()[0] -cl_context = cl.Context(properties=[(cl.context_properties.PLATFORM, cl_platform)]) -cl_queue = cl.CommandQueue(cl_context) - -cl_picture = cl.Buffer(cl_context, mf.WRITE_ONLY, size=config['size_x']*config['size_y']*3*np.float64(0).nbytes) -program = None - -with open('raymarch.cl') as f: - program = cl.Program(cl_context, Template(f.read()).substitute( - {**config, **earth} - )).build() +renderer = Renderer(config, earth) for time in np.arange(*time_range): pit = datetime(*config['date'], int(np.floor(time)), int((time-np.floor(time))*60), 0) sun_dir = sun_direction(config['latitude'], config['longitude'], pit, config['timezone'], 1.0 if config['summertime'] else 0.0) - sun = make_double3( + sun = ( np.cos(sun_dir[0])*np.sin(sun_dir[1]), np.cos(sun_dir[0])*np.cos(sun_dir[1]), np.sin(sun_dir[0]) ) print(sun_dir) - program.render_fisheye( - cl_queue, (config['size_x'], config['size_y']), None, cl_picture, - make_double3(*(config['eye_pos'] * earth['earth_radius'])), - make_double3(*(config['eye_dir'] * earth['earth_radius'])), - sun) - - np_picture = np.ndarray(shape=(config['size_y'], config['size_x'], 3), dtype=np.float64) - cl.enqueue_copy(cl_queue, np_picture, cl_picture).wait(); + np_picture = renderer.render_fisheye(sun) fig = plt.gcf() -- cgit v1.2.3